package com.jumi.microservice.service.pdd;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONArray;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.SendResult;
import com.aliyun.openservices.ons.api.bean.ProducerBean;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.jumi.microservice.common.constant.ResultEnum;
import com.jumi.microservice.common.exception.BaseException;
import com.jumi.microservice.common.utils.DateUtil;
import com.jumi.microservice.common.utils.HttpClientUtil;
import com.jumi.microservice.dto.CouponOrderMessage;
import com.jumi.microservice.dto.pdd.PddCpsUserInfoResponse;
import com.jumi.microservice.config.PddCpsConfig;
import com.jumi.microservice.entity.CouponOrder;
import com.jumi.microservice.enumerate.CouponOrderStatusEnum;
import com.jumi.microservice.enumerate.SourceEnum;
import com.jumi.microservice.mapper.CouponOrderMapper;
import com.jumi.microservice.utils.PddCreateSign;
import com.pdd.pop.sdk.common.util.JsonUtil;
import com.pdd.pop.sdk.http.PopAccessTokenClient;
import com.pdd.pop.sdk.http.PopClient;
import com.pdd.pop.sdk.http.PopHttpClient;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkOrderDetailGetRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkOrderListIncrementGetRequest;
import com.pdd.pop.sdk.http.api.pop.request.PddDdkResourceUrlGenRequest;
import com.pdd.pop.sdk.http.api.pop.response.*;
import com.pdd.pop.sdk.http.token.AccessTokenResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;

/**
 * @author scw
 * @date 2021/1/5
 */
@Service
public class PddCpsService {
    private static final Logger log = LoggerFactory.getLogger(PddCpsService.class);
    @Resource
    private PddCpsConfig pddCpsConfig;
    @Resource
    private CouponOrderMapper couponOrderMapper;
    @Resource
    private ProducerBean producerBean;
    @Resource
    private RedisTemplate redisTemplate;
    private static final String CPS_PDD_GOODS_RECOMMEND = "CpsPdd:GoodsRecommend::";

    /**
     * 根据code获取令牌相关信息
     *
     * @param code
     * @return
     */
    public PddCpsUserInfoResponse getInfoByCode(String code) {
        PddCpsUserInfoResponse pddCpsUserInfoResponse = new PddCpsUserInfoResponse();
        PopAccessTokenClient accessTokenClient = new PopAccessTokenClient(pddCpsConfig.getPddClientId(), pddCpsConfig.getPddClientSecret());
        try {
            AccessTokenResponse response = accessTokenClient.generate(code);
            pddCpsUserInfoResponse.setAccessToken(response.getAccessToken());
            pddCpsUserInfoResponse.setExpiresIn(response.getExpiresIn());
            pddCpsUserInfoResponse.setOwnerId(response.getOwnerId());
            pddCpsUserInfoResponse.setOwnerName(response.getOwnerName());
            pddCpsUserInfoResponse.setRefreshToken(response.getRefreshToken());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pddCpsUserInfoResponse;
    }

    /**
     * 充值中心
     *
     * @return
     */
    public String getRecharge(String pid, Integer resourceType) {
        PopClient client = new PopHttpClient(pddCpsConfig.getPddClientId(), pddCpsConfig.getPddClientSecret());
        PddDdkResourceUrlGenRequest request = new PddDdkResourceUrlGenRequest();
        request.setPid(pid);
        request.setResourceType(resourceType);
        PddDdkResourceUrlGenResponse response = null;
        try {
            response = client.syncInvoke(request);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return JsonUtil.transferToJson(response);
    }

    // https://gw-api.pinduoduo.com/api/router
    // ?type=pdd.ddk.resource.url.gen
    // &data_type=JSON
    // &client_id=dcc01df2059740f9837600d8fccf4b4f
    // &pid=13843797_186973390
    // &resource_type=39997
    // &timestamp=1610180333
    // &sign=E0291C118A7DB8B2B95457899FEB418D

    /**
     * CPS通用POST转发请求
     *
     * @return
     */
    public String cpsPostInfo(String jsonStr) {
        if ("".equals(jsonStr) || null == jsonStr) {
            throw new BaseException(ResultEnum.FAIL.getCode(), "JSON请求字符串不能为空!");
        }
        //全局佣金比例 == 请求接口
        double globalRate = (double) (50 / 100);
        Map jsonToMap = JSONObject.parseObject(jsonStr);
        Object obj = null;
        //redis缓存读取信息
        if ("pdd.ddk.goods.recommend.get".equals(jsonToMap.get("type"))) {
            String channelType = jsonToMap.get("channel_type").toString() == null ? "0" : jsonToMap.get("channel_type").toString();
            String page = jsonToMap.get("page").toString() == null ? "1" : jsonToMap.get("page").toString();
            String pageSize = jsonToMap.get("page_size").toString() == null ? "10" : jsonToMap.get("page_size").toString();
            String customParameters = jsonToMap.get("custom_parameters").toString() == null ? "0" : jsonToMap.get("custom_parameters").toString();
            String params = channelType + "-" + page + "-" + pageSize + "-" + customParameters;
            obj = redisTemplate.opsForValue().get(CPS_PDD_GOODS_RECOMMEND + params);
        }
        if (ObjectUtil.isNotNull(obj)) {
            log.info("redis缓存类型:[{}]", jsonToMap.get("type"));
            log.info("redis缓存读取信息:[{}]", obj.toString());
            return obj.toString();
        }
        String jsonStr2;
        SortedMap<String, Object> sortedMap = new TreeMap<>();
        JSONObject jsonObject = new JSONObject();
        Iterator iterMap = jsonToMap.keySet().iterator();
        if (iterMap.hasNext()) {
            do {
                String mapKey = iterMap.next().toString();
                Object mapVal = jsonToMap.get(mapKey);
                if (mapVal != null && !"".equals(mapVal.toString())) {
                    sortedMap.put(mapKey, mapVal);
                    jsonObject.put(mapKey, mapVal);
                }
            } while (iterMap.hasNext());
            sortedMap.put("data_type", "JSON");
            sortedMap.put("timestamp", System.currentTimeMillis());
            sortedMap.put("client_id", pddCpsConfig.getPddClientId());
            jsonObject.put("data_type", "JSON");
            jsonObject.put("timestamp", System.currentTimeMillis());
            jsonObject.put("client_id", pddCpsConfig.getPddClientId());
        }
        String sign = PddCreateSign.createSign(sortedMap, pddCpsConfig.getPddClientSecret());
        String jumpUrl = "https://gw-api.pinduoduo.com/api/router";
        jsonObject.put("sign", sign);
        jsonStr2 = HttpClientUtil.httpPost(jumpUrl, jsonObject.toJSONString());
        if ("pdd.ddk.goods.search".equals(jsonToMap.get("type"))) {
            //多多进宝商品查询：pdd.ddk.goods.search
            if (JSONObject.parseObject(jsonStr2).containsKey("goods_search_response")) {
                JSONObject parseObject = JSONObject.parseObject(jsonStr2).getJSONObject("goods_search_response");
                if (parseObject.containsKey("goods_list")) {
                    String goodsJson = parseObject.getString("goods_list");
                    if (goodsJson.length() > 0) {
                        JSONArray goodsArray = JSONArray.parseArray(goodsJson);
                        if (goodsArray.size() > 0) {
                            IntStream.range(0, goodsArray.size()).forEachOrdered(i -> {
                                JSONObject objJson = goodsArray.getJSONObject(i);
                                //佣金比例,千分比
                                if (objJson.containsKey("promotion_rate")) {
                                    objJson.put("promotion_rate", new DecimalFormat(".##").format(Double.valueOf(objJson.get("promotion_rate").toString()) * globalRate));
                                }
                                //比价行为预判定佣金，需要用户备案
                                if (objJson.containsKey("predict_promotion_rate")) {
                                    objJson.put("predict_promotion_rate", new DecimalFormat(".##").format(Double.valueOf(objJson.get("predict_promotion_rate").toString()) * globalRate));
                                }
                                goodsArray.set(i, objJson);
                            });
                            parseObject.put("goods_list", goodsArray);
                            JSONObject parseObjectJson = new JSONObject();
                            parseObjectJson.put("goods_search_response", parseObject);
                            jsonStr2 = parseObjectJson.toJSONString();
                        }
                    }
                }
            }
        } else if ("pdd.ddk.goods.recommend.get".equals(jsonToMap.get("type"))) {
            //多多进宝商品推荐API：pdd.ddk.goods.recommend.get
            if (JSONObject.parseObject(jsonStr2).containsKey("goods_basic_detail_response")) {
                JSONObject parseObject = JSONObject.parseObject(jsonStr2).getJSONObject("goods_basic_detail_response");
                if (parseObject.containsKey("list")) {
                    String listJson = parseObject.getString("list");
                    if (listJson.length() > 0) {
                        JSONArray listArray = JSONArray.parseArray(listJson);
                        if (listArray.size() > 0) {
                            IntStream.range(0, listArray.size()).forEachOrdered(i -> {
                                JSONObject objJson = listArray.getJSONObject(i);
                                //佣金比例,千分比
                                if (objJson.containsKey("promotion_rate")) {
                                    objJson.put("promotion_rate", new DecimalFormat(".##").format(Double.valueOf(objJson.get("promotion_rate").toString()) * globalRate));
                                }
                                //比价行为预判定佣金，需要用户备案
                                if (objJson.containsKey("predict_promotion_rate")) {
                                    objJson.put("predict_promotion_rate", new DecimalFormat(".##").format(Double.valueOf(objJson.get("predict_promotion_rate").toString()) * globalRate));
                                }
                                listArray.set(i, objJson);
                            });
                            parseObject.put("list", listArray);
                            JSONObject parseObjectJson = new JSONObject();
                            parseObjectJson.put("goods_basic_detail_response", parseObject);
                            jsonStr2 = parseObjectJson.toJSONString();
                            String channelType = jsonToMap.get("channel_type").toString() == null ? "0" : jsonToMap.get("channel_type").toString();
                            String page = jsonToMap.get("page").toString() == null ? "1" : jsonToMap.get("page").toString();
                            String pageSize = jsonToMap.get("page_size").toString() == null ? "10" : jsonToMap.get("page_size").toString();
                            String customParameters = jsonToMap.get("custom_parameters").toString() == null ? "0" : jsonToMap.get("custom_parameters").toString();
                            String params = channelType + "-" + page + "-" + pageSize + "-" + customParameters;
                            redisTemplate.opsForValue().setIfAbsent(CPS_PDD_GOODS_RECOMMEND + params, jsonStr2, 5, TimeUnit.MINUTES);
                        }
                    }
                }
            }
        } else if ("pdd.ddk.goods.detail".equals(jsonToMap.get("type"))) {
            //多多进宝商品详情查询：pdd.ddk.goods.detail
            if (JSONObject.parseObject(jsonStr2).containsKey("goods_detail_response")) {
                JSONObject parseObject = JSONObject.parseObject(jsonStr2).getJSONObject("goods_detail_response");
                if (parseObject.containsKey("goods_details")) {
                    String goodsDetailsJson = parseObject.getString("goods_details");
                    if (goodsDetailsJson.length() > 0) {
                        JSONArray goodsDetailsArray = JSONArray.parseArray(goodsDetailsJson);
                        if (goodsDetailsArray.size() > 0) {
                            IntStream.range(0, goodsDetailsArray.size()).forEachOrdered(i -> {
                                JSONObject objJson = goodsDetailsArray.getJSONObject(i);
                                //佣金比例,千分比
                                if (objJson.containsKey("promotion_rate")) {
                                    objJson.put("promotion_rate", new DecimalFormat(".##").format(Double.valueOf(objJson.get("promotion_rate").toString()) * globalRate));
                                }
                                //比价行为预判定佣金，需要用户备案
                                if (objJson.containsKey("predict_promotion_rate")) {
                                    objJson.put("predict_promotion_rate", new DecimalFormat(".##").format(Double.valueOf(objJson.get("predict_promotion_rate").toString()) * globalRate));
                                }
                                goodsDetailsArray.set(i, objJson);
                            });
                            parseObject.put("goods_details", goodsDetailsArray);
                            JSONObject parseObjectJson = new JSONObject();
                            parseObjectJson.put("goods_detail_response", parseObject);
                            jsonStr2 = parseObjectJson.toJSONString();
                        }
                    }
                }
            }
        }
        return jsonStr2;
    }

    /**
     * 每个月22号零点更新订单状态
     */
    @Scheduled(cron = "0 0 0 22 * ?")
//    @Scheduled(fixedDelay = 1000*60)
    public void scheduledGetOrderStatus() {
        log.info("定时更新拼多多订单状态任务 进入 ==>");
        PopClient client = new PopHttpClient(pddCpsConfig.getPddClientId(), pddCpsConfig.getPddClientSecret());
        QueryWrapper<CouponOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.le("order_status", 3).eq("source", SourceEnum.PDD.getCode());
        List<CouponOrder> couponOrders = couponOrderMapper.selectList(queryWrapper);
        if (couponOrders.isEmpty()) {
            log.info("未查询到拼多多订单数据");
            return;
        }
        PddDdkOrderDetailGetRequest request = new PddDdkOrderDetailGetRequest();
        request.setQueryOrderType(1);
        for (CouponOrder couponOrder : couponOrders) {
            CouponOrder oldCouponOrder = new CouponOrder();
            BeanUtils.copyProperties(couponOrder, oldCouponOrder);
            request.setOrderSn(couponOrder.getOrderSn());
            try {
                PddDdkOrderDetailGetResponse response = client.syncInvoke(request);
                couponOrder.setOrderStatus(response.getOrderDetailResponse().getOrderStatus().byteValue());
                couponOrder.setOrderStatusDesc(response.getOrderDetailResponse().getOrderStatusDesc());
                couponOrder.setGoodsPrice(new BigDecimal(response.getOrderDetailResponse().getGoodsPrice()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP));
                couponOrder.setGoodsQuantity(response.getOrderDetailResponse().getGoodsQuantity().intValue());
                couponOrder.setPayAmount(new BigDecimal(response.getOrderDetailResponse().getOrderAmount()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP));
                couponOrder.setPromotionAmount(new BigDecimal(response.getOrderDetailResponse().getPromotionAmount()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP));
                if (response.getOrderDetailResponse().getOrderSettleTime() != null) {
                    Date date = new Date(response.getOrderDetailResponse().getOrderSettleTime() * 1000);
                    couponOrder.setSettlementTime(date);
                }
                /*
                 * 聚米订单状态: 1 已付款, 2 已结算, 3 已失效
                 * 拼多多订单状态：0-已支付；1-已成团；2-确认收货；3-审核成功；4-审核失败（不可提现）；5-已经结算；8-非多多进宝商品（无佣金订单）
                 */
                byte couponOrderStatus;
                if (response.getOrderDetailResponse().getOrderStatus().byteValue() == 5) {
                    couponOrderStatus = CouponOrderStatusEnum.ORDER_SETTLED.getCode();
                } else if (response.getOrderDetailResponse().getOrderStatus().byteValue() < 4) {
                    couponOrderStatus = CouponOrderStatusEnum.ORDER_PAY.getCode();
                } else {
                    couponOrderStatus = CouponOrderStatusEnum.ORDER_EXPIRED.getCode();
                }
                couponOrder.setCouponOrderStatus(couponOrderStatus);
                log.info("定时更新拼多多订单状态任务 原始数据[{}] 更新数据 [{}]", JSON.toJSONString(oldCouponOrder), JSON.toJSONString(couponOrder));
                if (isExist(couponOrder)) {
                    if (couponOrderMapper.updateById(couponOrder) > 0) {
                        CouponOrderMessage couponOrderMessage = new CouponOrderMessage();
                        BeanUtils.copyProperties(couponOrder, couponOrderMessage);
                        Message message = new Message("couponOrder", "", "", JSON.toJSONBytes(couponOrderMessage));
                        SendResult sendResult = producerBean.send(message);
                        log.info("拼多多订单[{}]发送消息, 消息ID[{}]", couponOrder.getOrderSn(), sendResult.getMessageId());
                    }
                }
            } catch (Exception e) {
                log.info("定时更新拼多多订单状态任务 出错 原始数据[{}],错误描述[{}]", JSON.toJSONString(couponOrder), e.getMessage());
            }
        }
    }

    /**
     * 定时拉取订单列表
     */
    @Scheduled(fixedDelay = 1000 * 60)
    public void scheduledGetOrderListRange() {
        log.info("定时拉取拼多多订单任务 进入 ==>");
        PopClient client = new PopHttpClient(pddCpsConfig.getPddClientId(), pddCpsConfig.getPddClientSecret());
        PddDdkOrderListIncrementGetRequest request = new PddDdkOrderListIncrementGetRequest();
        QueryWrapper<CouponOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("last_order_id").orderByDesc("last_order_id").last("Limit 1")
                .eq("source", SourceEnum.PDD.getCode());
        CouponOrder couponOrder = couponOrderMapper.selectOne(queryWrapper);
        request.setCashGiftOrder(false);
        request.setPage(1);
        request.setPageSize(50);
        request.setQueryOrderType(1);
        request.setReturnCount(true);
        Date date = new Date();
        request.setEndUpdateTime(date.getTime() / 1000);
        if (couponOrder != null) {
            request.setStartUpdateTime(Long.parseLong(couponOrder.getLastOrderId()));
        } else {
            request.setStartUpdateTime(DateUtil.getDateAfterDay(date, -1).getTime() / 1000);
        }
        int count = 1;
        for (int p = 1; p <= count; p++) {
            try {
                request.setPage(p);
                PddDdkOrderListIncrementGetResponse response = client.syncInvoke(request);
                long total = response.getOrderListGetResponse().getTotalCount();
                count = (int) (total % 50 == 0 ? total / 50 : total / 50 + 1);
                log.info("定时分页拉取拼多多订单任务 pageNum [{}]  pageSize [{}] total [{}] 获取数据 [{}]", p, 50, total, JSON.toJSONString(response));
                List<PddDdkOrderListIncrementGetResponse.OrderListGetResponseOrderListItem> orderList =
                        response.getOrderListGetResponse().getOrderList();
                if (orderList.isEmpty()) {
                    log.info("定时分页拉取拼多多订单任务未查询到数据");
                    return;
                }
                for (PddDdkOrderListIncrementGetResponse.OrderListGetResponseOrderListItem item : orderList) {
                    couponOrder = new CouponOrder();
                    couponOrder.setLastOrderId(item.getOrderModifyAt().toString());
                    couponOrder.setSource(SourceEnum.PDD.getCode());
                    couponOrder.setOrderSn(item.getOrderSn());
                    couponOrder.setUid(item.getCustomParameters() != null && !item.getCustomParameters().isEmpty()
                            ? Long.valueOf(item.getCustomParameters().replace("{\"uid\":\"","").replace("\"}","")) : null);
                    couponOrder.setBatchNo(item.getBatchNo());
                    couponOrder.setGoodsId(item.getGoodsId());
                    couponOrder.setGoodsImage(item.getGoodsThumbnailUrl());
                    couponOrder.setGoodsPrice(new BigDecimal(item.getOrderAmount()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP));
                    couponOrder.setGoodsQuantity(item.getGoodsQuantity().intValue());
                    couponOrder.setOrderStatusDesc(item.getOrderStatusDesc());
                    couponOrder.setOrderStatus(item.getOrderStatus().byteValue());
                    couponOrder.setGoodsTitle(item.getGoodsName());
                    date = new Date(item.getOrderCreateTime() * 1000);
                    couponOrder.setOrderTime(date);
                    couponOrder.setPayAmount(new BigDecimal(item.getOrderAmount()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP));
                    couponOrder.setPromotionAmount(new BigDecimal(item.getPromotionAmount()).divide(BigDecimal.valueOf(100), 2, BigDecimal.ROUND_HALF_UP));
                    date = new Date(item.getOrderPayTime() * 1000);
                    couponOrder.setPayTime(date);
                    if (item.getOrderSettleTime() != null) {
                        date = new Date(item.getOrderSettleTime() * 1000);
                        couponOrder.setSettlementTime(date);
                    }
                    couponOrder.setPromotionId(item.getPId());
                    couponOrder.setPromotionRate(BigDecimal.valueOf(item.getPromotionRate()).divide(BigDecimal.valueOf(1000), 4, BigDecimal.ROUND_HALF_UP));
                    /*
                     * 聚米订单状态: 1 已付款, 2 已结算, 3 已失效
                     * 拼多多订单状态：0-已支付；1-已成团；2-确认收货；3-审核成功；4-审核失败（不可提现）；5-已经结算；8-非多多进宝商品（无佣金订单）
                     */
                    byte couponOrderStatus;
                    if (item.getOrderStatus().byteValue() == 5) {
                        couponOrderStatus = CouponOrderStatusEnum.ORDER_SETTLED.getCode();
                    } else if (item.getOrderStatus().byteValue() < 4) {
                        couponOrderStatus = CouponOrderStatusEnum.ORDER_PAY.getCode();
                    } else {
                        couponOrderStatus = CouponOrderStatusEnum.ORDER_EXPIRED.getCode();
                    }
                    couponOrder.setCouponOrderStatus(couponOrderStatus);
                    int res = 0;
                    Boolean flag = isExist(couponOrder);
                    log.info("判断订单结果 [{}]", flag);
                    if (flag != null && flag) {
                        log.info("该订单存在且需要更新 更新==>");
                        UpdateWrapper<CouponOrder> updateWrapper = new UpdateWrapper<>();
                        updateWrapper.eq("order_sn", couponOrder.getOrderSn());
                        res = couponOrderMapper.update(couponOrder, updateWrapper);
                    } else if (flag == null) {
                        log.info("该订单不存在 插入==>");
                        res = couponOrderMapper.insert(couponOrder);
                    }
                    if (res > 0) {
                        CouponOrderMessage couponOrderMessage = new CouponOrderMessage();
                        BeanUtils.copyProperties(couponOrder, couponOrderMessage);
                        Message message = new Message("couponOrder", "", "", JSON.toJSONBytes(couponOrderMessage));
                        SendResult sendResult = producerBean.send(message);
                        log.info("拼多多订单[{}]发送消息, 消息ID[{}]", couponOrder.getOrderSn(), sendResult.getMessageId());
                    }
                }
            } catch (Exception e) {
                log.info("定时分页拉取拼多多订单出错 [{}]", e.getMessage());
                return;
            }
        }
        log.info("定时分页拉取拼多多订单完成");
    }


    /**
     * 判断订单是否已存在
     *
     * @param newCouponOrder
     * @return
     */
    public Boolean isExist(CouponOrder newCouponOrder) {
        QueryWrapper<CouponOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("order_sn", newCouponOrder.getOrderSn());
        CouponOrder oldCouponOrder = couponOrderMapper.selectOne(queryWrapper);
        if (oldCouponOrder == null) {
            //不存在
            return null;
        }
        //存在 验证是否需要更新发消息
        if (oldCouponOrder.getCouponOrderStatus().equals(newCouponOrder.getCouponOrderStatus())
//                && newCouponOrder.getSettlementTime().equals(oldCouponOrder.getSettlementTime())
                && oldCouponOrder.getGoodsPrice().compareTo(newCouponOrder.getGoodsPrice()) == 0
                && oldCouponOrder.getGoodsQuantity().equals(newCouponOrder.getGoodsQuantity())
                && oldCouponOrder.getPayAmount().compareTo(newCouponOrder.getPayAmount()) == 0
                && oldCouponOrder.getPromotionAmount().compareTo(newCouponOrder.getPromotionAmount()) == 0) {
            return false;
        }
        return true;
    }
}

